package com.example.service;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class HazelcastServiceImpl implements HazelcastService, InitializingBean {

    private HazelcastInstance hazelcastInstance;

    @Value("${hazelcast.url}")
    private String url;

    @Override
    public void afterPropertiesSet() throws Exception {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.getNetworkConfig().addAddress(url);
        clientConfig.getNetworkConfig().setSmartRouting(false);
        this.hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
    }

    @Override
    public HazelcastInstance getHazelcastInstance() {
        return this.hazelcastInstance;
    }
}
